package cn.practice.chat.feign.api;

import cn.practice.chat.entity.User;
import cn.practice.chat.feign.service.UserDetailFeign;
import cn.practice.chat.lang.Result;
import cn.practice.chat.response.user.LoginUser;
import cn.practice.chat.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName UserDetailFeignImpl
 * @Description:
 * @Author A-TAO
 * @Date 2022/10/31
 * @Version V1.0
 **/
@Slf4j
@RestController
public class UserDetailFeignImpl implements UserDetailFeign {

    @Autowired
    private UserService userService;

    @Override
    public Result<LoginUser> getUser(String username) {
        LoginUser response = null;
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getUsername, username);

        User user = userService.getOne(queryWrapper);
        if(user != null){
            response = new LoginUser();
            BeanUtils.copyProperties(user, response);
        }
        log.info("UserDetailFeign查询用户详情，username={}, result={}", username, response);
        return Result.success(response);
    }
}
